{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-04-30T17:02:10.178049Z",
     "start_time": "2025-04-30T17:02:09.853084Z"
    }
   },
   "source": "import numpy as np",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "二维数组运算",
   "id": "5c2a65be34f1d39f"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-30T17:09:35.136123Z",
     "start_time": "2025-04-30T17:09:35.110124Z"
    }
   },
   "cell_type": "code",
   "source": [
    "interest_score = np.random.randint(10, size=(4, 3))\n",
    "print('interest_score:')\n",
    "print(interest_score)\n",
    "print('np.sum axis=0: ', np.sum(interest_score, axis=0))\n",
    "print('np.sum axis=1: ', np.sum(interest_score, axis=1))\n",
    "print('np.average axis=1: ', np.average(interest_score, axis=1)) #取平均成绩"
   ],
   "id": "f407fb7906c81e1f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "interest_score:\n",
      "[[4 9 3]\n",
      " [1 2 6]\n",
      " [9 6 5]\n",
      " [3 5 9]]\n",
      "np.sum axis=0:  [17 22 23]\n",
      "np.sum axis=1:  [16  9 20 17]\n",
      "np.average axis=1:  [5.33333333 3.         6.66666667 5.66666667]\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "多维数组运算",
   "id": "d080faa7a7145fe3"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "73c43f7ab34a3bcc"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-28T18:19:32.633153Z",
     "start_time": "2025-04-28T18:19:32.617154Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.arange(120).reshape(2,3,4,5)\n",
    "a"
   ],
   "id": "51a40bc28389812a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[[  0,   1,   2,   3,   4],\n",
       "         [  5,   6,   7,   8,   9],\n",
       "         [ 10,  11,  12,  13,  14],\n",
       "         [ 15,  16,  17,  18,  19]],\n",
       "\n",
       "        [[ 20,  21,  22,  23,  24],\n",
       "         [ 25,  26,  27,  28,  29],\n",
       "         [ 30,  31,  32,  33,  34],\n",
       "         [ 35,  36,  37,  38,  39]],\n",
       "\n",
       "        [[ 40,  41,  42,  43,  44],\n",
       "         [ 45,  46,  47,  48,  49],\n",
       "         [ 50,  51,  52,  53,  54],\n",
       "         [ 55,  56,  57,  58,  59]]],\n",
       "\n",
       "\n",
       "       [[[ 60,  61,  62,  63,  64],\n",
       "         [ 65,  66,  67,  68,  69],\n",
       "         [ 70,  71,  72,  73,  74],\n",
       "         [ 75,  76,  77,  78,  79]],\n",
       "\n",
       "        [[ 80,  81,  82,  83,  84],\n",
       "         [ 85,  86,  87,  88,  89],\n",
       "         [ 90,  91,  92,  93,  94],\n",
       "         [ 95,  96,  97,  98,  99]],\n",
       "\n",
       "        [[100, 101, 102, 103, 104],\n",
       "         [105, 106, 107, 108, 109],\n",
       "         [110, 111, 112, 113, 114],\n",
       "         [115, 116, 117, 118, 119]]]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 22
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-28T18:19:41.388798Z",
     "start_time": "2025-04-28T18:19:41.373798Z"
    }
   },
   "cell_type": "code",
   "source": "np.sum(a, axis=1)",
   "id": "48ab254c409434de",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 60,  63,  66,  69,  72],\n",
       "        [ 75,  78,  81,  84,  87],\n",
       "        [ 90,  93,  96,  99, 102],\n",
       "        [105, 108, 111, 114, 117]],\n",
       "\n",
       "       [[240, 243, 246, 249, 252],\n",
       "        [255, 258, 261, 264, 267],\n",
       "        [270, 273, 276, 279, 282],\n",
       "        [285, 288, 291, 294, 297]]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 23
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
